package com.czh.mock.providers.text.address;

import java.util.HashMap;
import java.util.Map;

/**
 * 生成地址数据的配置类
 *
 * @author manem
 */
public class AddressConfig {
    /**
     * 限定省份
     */
    private boolean fixedProvince = false;
    /**
     * 限定城市
     */
    private boolean fixedCity = false;
    /**
     * 限定区县
     */
    private boolean fixedDistrict = false;
    /**
     * 限定小区
     */
    private boolean fixedResidence = false;
    /**
     * 地址的层级
     * 默认是精确到小区房间号
     */
    private int level;
    /**
     * 缓存已生成的省份、市、区等信息
     * 用于限定范围时使用
     */
    private Map<String, GdDistrictEntity.District> cache = new HashMap<>();
    /**
     * 缓存已生成的小区信息
     * 用于限定范围时使用
     */
    private Map<String, String> cacheString = new HashMap<>();
    public static final String CACHE_PROVINCE = "province";
    public static final String CACHE_CITY = "city";
    public static final String CACHE_DISTRICT = "district";
    public static final String CACHE_RESIDENCE = "residence";
    public static final String CACHE_STREET = "street";
    /**
     * 地址级别到达省
     */
    public static final int LEVEL_PROVINCE = 1;
    /**
     * 地址级别到达市
     */
    public static final int LEVEL_CITY = 2;
    /**
     * 地址级别到达区
     */
    public static final int LEVEL_DISTRICT = 3;
    /**
     * 地址级别到达小区
     */
    public static final int LEVEL_RESIDENCE = 4;

    private AddressConfig() {
    }


    public static AddressConfig build() {
        return new AddressConfig();
    }

    public boolean needCacheProvince() {
        return fixedProvince || fixedCity || fixedDistrict || fixedResidence;
    }

    public boolean needCacheCity() {
        return fixedCity || fixedDistrict || fixedResidence;
    }

    public boolean needCacheDistrict() {
        return fixedDistrict || fixedResidence;
    }

    public boolean needCacheResidence() {
        return fixedResidence;
    }

    public Map<String, GdDistrictEntity.District> getCache() {
        return cache;
    }

    public Map<String, String> getCacheString() {
        return cacheString;
    }

    public boolean isFixedProvince() {
        return fixedProvince;
    }

    public AddressConfig setFixedProvince(boolean fixedProvince) {
        this.fixedProvince = fixedProvince;
        return this;
    }

    public boolean isFixedCity() {
        return fixedCity;
    }

    public AddressConfig setFixedCity(boolean fixedCity) {
        this.fixedCity = fixedCity;
        return this;
    }

    public boolean isFixedDistrict() {
        return fixedDistrict;
    }

    public AddressConfig setFixedDistrict(boolean fixedDistrict) {
        this.fixedDistrict = fixedDistrict;
        return this;
    }

    public boolean isFixedResidence() {
        return fixedResidence;
    }

    public AddressConfig setFixedResidence(boolean fixedResidence) {
        this.fixedResidence = fixedResidence;
        return this;
    }

    public int getLevel() {
        return level;
    }

    public AddressConfig setLevel(int level) {
        this.level = level;
        return this;
    }
}
